package dimension.starry.gui.Component;

import com.mojang.blaze3d.systems.RenderSystem;
import dimension.starry.StarryDimension;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
import net.minecraft.client.gui.tooltip.Tooltip;
import net.minecraft.client.gui.widget.ClickableWidget;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

@Environment(EnvType.CLIENT)
public class StatusWidget extends ClickableWidget {

    private static final Text stringTextComponent = Text.empty();
    private static final Identifier BACKGROUND_RESOURCE = new Identifier(
        StarryDimension.MOD_ID, "textures/gui/player_info/status_card.png");

    private final Identifier iconResource;
    private final Function<ClientPlayerEntity, String> labelText;

    public StatusWidget(int left, int top, Function<ClientPlayerEntity, String> labelText, String name) {
        super(left, top, 38, 20, stringTextComponent);
        this.labelText = labelText;
        this.iconResource = new Identifier(StarryDimension.MOD_ID, "textures/gui/player_info/" + name + ".png");
        this.setTooltip(Tooltip.of(Text.translatable(StarryDimension.MOD_ID + ".gui.player_info.label." + name)));
    }

    @Override
    protected void renderButton(DrawContext drawContext, int mouseX, int mouseY, float delta) {
        drawContext.drawTexture(BACKGROUND_RESOURCE, this.getX(), this.getY(), 0, 0, width, height, width, height);
        drawContext.drawTexture(iconResource, this.getX() + 5, this.getY() + 5, 0, 0, 10, 10, 10, 10);
        drawContext.drawTextWithShadow(
            MinecraftClient.getInstance().textRenderer, labelText.apply(MinecraftClient.getInstance().player),
            this.getX() + 19, this.getY() + 6, 16777215
        );
    }

    @Override
    protected void appendClickableNarrations(NarrationMessageBuilder builder) {}

}
